﻿@using System.Web.Mvc.Html
@using ALinq.BBS
@using ALinq.BBS.DataAccess
@using ALinq.BBS.Models
@using ALinq.BBS.App_GlobalResources
@{
    var board = (Board)Model.Board;
    var forum = (Forum)Model.Forum;
    var postList = (PostList)Model.PostList;

    Layout = "_Layout.cshtml";
    PageData["Css"] = "PostList.css";
    PageData["Title"] = board.Name;

    Func<int, string> createUrl = delegate(int pageIndex)
    {
        var obj = new { boardID = board.ID, forumID = forum.ID, postListIndex = pageIndex };
        return Url.RouteUrl(RouteNames.PostList, obj);
    };

    var pagingModel = new PagingModel(forum.Posts.Count, forum.Posts.PagesCount, postList.Index, createUrl);

    var navigateForums = new Stack<Forum>();
    var p = forum;
    while (p != null)
    {
        navigateForums.Push(p);
        p = p.Parent;
    }

    IEnumerable<Forum> tabForums = new Forum[] { };
    if (forum.Children.Count != 0)
    {
        tabForums = new[] { navigateForums.Peek() }.Union(forum.Children);
    }
    else if (forum.Parent != null)
    {
        tabForums = new[] { navigateForums.Peek() }.Union(forum.Parent.Children);
    }
}
@helper ForumTitle(Board board, Forum forum)
    {
    <a href="@Url.RouteUrl(RouteNames.PostList, new { boardID = board.ID, forumID = forum.ID })">
        <span class="pageTitle">@forum.Name</span></a> 
}
<div class="pageTitle" style="float: left;">
    @foreach (var item in navigateForums)
    {
        @ForumTitle(board, item);
                                if (item != forum)
                                { 
        <span>- </span>
                                }
    }
</div>
<div class="HackBox">
</div>
<div>
    <div style="float: left">
        <a id="urlAddPost" href="@Url.RouteUrl(RouteNames.EditPost, new { boardID = board.ID, forumID = forum.ID, postListIndex = postList.Index })">
            <img alt="@Resources.Images.NewPost" src="@Url.Content("~/Content/Images/Button/NewPost.gif")" /></a>
    </div>
    <div style="float: right; text-align: right; vertical-align: bottom; padding-top: 10px;">
        @RenderPage("../Shared/Controls/PagingBar.cshtml", pagingModel)
    </div>
</div>
<div class="HackBox">
</div>
@foreach (var item in tabForums)
{
    var name = item.Name;
    if (item == tabForums.First())
    {
        name = Label.All;
    }
    <div style="width: 146px; float: left;">
        @if (forum.ID == item.ID)
        {
            <div class="ChildBoardSelected">
                @name
            </div>
            <div class="ChildBoardSelectedRight">
            </div>
        }
        else
        {
            <div class="ChildBoardUnselect">
                @Html.RouteLink(name, RouteNames.PostList, new { boardID = board.ID, forumID = item.ID })
            </div>
            <div class="ChildBoardUnselectRight">
            </div>
        }
    </div>
}
<div class="HackBox">
</div>
<div style="float: right; width: 120px;" class="postListHeader">
    @Label.LastReply</div>
<div style="float: right; width: 120px;" class="postListHeader">
    @Label.TopicStarter</div>
<div style="float: right; width: 120px;" class="postListHeader">
    @Label.Replies / @Label.Views</div>
<div class="postListHeader">
    @Label.Title</div>
<div class="HackBox">
</div>
@foreach (var post in postList)
{
    <div class="postListItem">
        <div id="chkPostID" style="float: left; padding-top: 10px;" runat="server">
            <input type="checkbox" name="id" value="@post.ID" style="display: none;" />
        </div>
        <div style="float: left; width: 20px; padding-top: 10px;">
            <img src="@this.ArticleIcon(post)" alt="PostIcon" />
        </div>
        <div style="float: right; width: 120px; padding-top: 2px;">
            <div>
                @(post.LastReply != null ? " " : " ")
            </div>
            <div>
                <a href="">
                    @(post.LastReply != null ? post.LastReply.UserName : " ")</a></div>
        </div>
        <div style="float: right; width: 120px; padding-top: 2px;">
            <div>
                @post.Date
            </div>
            <div>
                @this.CreateUserPageLink(post.UserName)
            </div>
        </div>
        <div style="float: right; width: 80px; padding-top: 10px; text-align: left;">
            @post.Replies.Count/@*<%#Eval("HitCount") %>*@</div>
        <div style="text-align: left; padding-top: 12px">
            @Html.RouteLink(post.Title, RouteNames.Post, new { boardID = board.ID, forumID = forum.ID, postListIndex = postList.Index, postID = post.ID, returnUrl = Request.RawUrl })
        </div>
    </div>
    <div class="HackBox">
    </div>

}
<div style="text-align: right;">
    @RenderPage("../Shared/Controls/PagingBar.cshtml", pagingModel)
</div>
